package com.spider.spiderorderadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spider.spiderorderadmin.entity.model.SystemRoleResource;
import com.spider.spiderorderadmin.entity.model.User;
import com.spider.spiderorderadmin.mapper.RoleResourceMapper;
import com.spider.spiderorderadmin.service.SystemRoleResourceService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2024/5/17 7:53 下午
 */
@Service
public class SystemRoleResourceServiceImpl extends ServiceImpl<RoleResourceMapper, SystemRoleResource>
        implements SystemRoleResourceService {


    @Override
    public Integer deleteByResourceIds(Long roleId, List<Long> resourceIds) {
        LambdaQueryWrapper<SystemRoleResource> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SystemRoleResource::getRoleId, roleId);
        queryWrapper.in(SystemRoleResource::getResourceId, resourceIds);
        return this.baseMapper.delete(queryWrapper);
    }

    @Override
    public Integer deleteByRoleId(Long roleId) {
        LambdaQueryWrapper<SystemRoleResource> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SystemRoleResource::getRoleId, roleId);
        return this.baseMapper.delete(queryWrapper);
    }

    @Override
    public List<Long> selectResourceByRoleId(Long roleId) {
        LambdaQueryWrapper<SystemRoleResource> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SystemRoleResource::getRoleId, roleId);
        List<SystemRoleResource> roleResourceList = this.baseMapper.selectList(queryWrapper);
        return roleResourceList.stream().map(SystemRoleResource::getResourceId).collect(Collectors.toList());
    }
}
